home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / scripts.vim < prev    next >
Encoding:
Text File  |  2001-09-05  |  5.3 KB  |  212 lines

  1. " Vim support file to detect file types in scripts
  2. "
  3. " Maintainer:    Bram Moolenaar <Bram@vim.org>
  4. " Last change:    2001 Sep 05
  5.  
  6. " This file is called by an autocommand for every file that has just been
  7. " loaded into a buffer.  It checks if the type of file can be recognized by
  8. " the file contents.  The autocommand is in $VIMRUNTIME/filetype.vim.
  9.  
  10.  
  11. " Load the user defined scripts file first
  12. " Only do this when the FileType autocommand has not been triggered yet
  13. if !did_filetype() && exists("myscriptsfile") && file_readable(expand(myscriptsfile))
  14.   execute "source " . myscriptsfile
  15. endif
  16.  
  17. " Only do this when the FileType autocommand has not been triggered yet
  18. if did_filetype()
  19.   finish
  20. endif
  21.  
  22. " Line continuation is used here, remove 'C' from 'cpoptions'
  23. let s:cpo_save = &cpo
  24. set cpo&vim
  25.  
  26. let s:line1 = getline(1)
  27.  
  28. " Check for a line like "#!/usr/bin/env bash".  Turn it into "#!/usr/bin/bash"
  29. " to make matching easier.
  30. if s:line1 =~ '^#!.*[/\\]env\s'
  31.   let s:line1 = substitute(s:line1, '\<env\s\+', '', '')
  32. endif
  33.  
  34. " Bourne-like shell scripts: sh ksh bash bash2
  35. if s:line1 =~ '^#!.*[/\\]\(bash\|bash2\|ksh\|sh\)\>' || s:line1 =~ '^:$'
  36.   call SetFileTypeSH(s:line1)    " defined in filetype.vim
  37.  
  38. " csh and tcsh scripts
  39. elseif s:line1 =~ '^#!.*[/\\]t\=csh\>'
  40.   set ft=csh
  41.  
  42. " Z shell scripts
  43. elseif s:line1 =~ '^#!.*[/\\]zsh\>'
  44.     \ || s:line1 =~ '^#compdef\>'
  45.     \ || s:line1 =~ '^#autoload\>'
  46.   set ft=zsh
  47.  
  48. " TCL scripts
  49. elseif s:line1 =~ '^#!.*[/\\]\(tclsh\|wish\|expectk\|itclsh\|itkwish\)\>'
  50.   set ft=tcl
  51.  
  52. " ELM Mail files
  53. elseif s:line1 =~ '^From [a-zA-Z][a-zA-Z_0-9\.=-]*\(@[^ ]*\)\= .*[12][09]\d\d$'
  54.   set ft=mail
  55.  
  56. " Expect scripts
  57. elseif s:line1 =~ '^#!.*[/\\]expect\>'
  58.   set ft=expect
  59.  
  60. " Gnuplot scripts
  61. elseif s:line1 =~ '^#!.*[/\\]gnuplot\>'
  62.   set ft=gnuplot
  63.  
  64. " Makefiles
  65. elseif s:line1 =~ '^#!.*[/\\][^/\\]*make\>'
  66.   set ft=make
  67.  
  68. " Mason
  69. elseif s:line1 =~ '^<[%&].*>'
  70.   set ft=mason
  71.  
  72. " Perl
  73. elseif s:line1 =~ '^#!.*[/\\][^/\\]*perl[^/\\]*\>'
  74.   set ft=perl
  75.  
  76. " Python
  77. elseif s:line1 =~ '^#!.*[/\\][^/\\]*python[^/\\]*\>'
  78.   set ft=python
  79.  
  80. " Ruby
  81. elseif s:line1 =~ '^#!.*[/\\][^/\\]*ruby[^/\\]*\>'
  82.   set ft=ruby
  83.  
  84. " BC calculator
  85. elseif s:line1 =~ '^#!.*[/\\]bc\>'
  86.   set ft=bc
  87.  
  88. " sed
  89. elseif s:line1 =~ '^#!.*sed\>'
  90.   set ft=sed
  91.  
  92. " OCaml-scripts
  93. elseif s:line1 =~ '^#!.*[/\\][^/\\]*ocaml[^/\\]*\>'
  94.   set ft=ocaml
  95.  
  96. " Vim scripts (must have '" vim' as the first line to trigger this)
  97. elseif s:line1 =~ '^" *[vV]im$'
  98.   set ft=vim
  99.  
  100. " Diff file:
  101. " - "diff" in first line (context diff)
  102. " - "Only in " in first line
  103. " - "--- " in first line and "+++ " in second line (unified diff).
  104. " - "*** " in first line and "--- " in second line (context diff).
  105. " - "# It was generated by makepatch " in the second line (makepatch diff).
  106. " - "Index: <filename>" in the first line (CVS file)
  107. elseif s:line1 =~ '^diff\>' || s:line1 =~ '^Only in '
  108.     \ || (s:line1 =~ '^--- ' && getline(2) =~ '^+++ ')
  109.     \ || (s:line1 =~ '^\*\*\* ' && getline(2) =~ '^--- ')
  110.     \ || s:line1 =~ '^\d\+\(,\d\+\)\=[cda]\d\+\>'
  111.     \ || getline(2) =~ '^# It was generated by makepatch '
  112.     \ || s:line1 =~ '^Index:\s\+\f\+$'
  113.     \ || s:line1 =~ '^==== //\f\+#\d\+'
  114.   set ft=diff
  115.  
  116. " PostScript Files (must have %!PS as the first line, like a2ps output)
  117. elseif s:line1 =~ '^%![ \t]*PS'
  118.   set ft=postscr
  119.  
  120. " Awk scripts
  121. elseif s:line1 =~ '^#!.*awk\>'
  122.   set ft=awk
  123.  
  124. " M4 scripts: Guess there is a line that starts with "dnl".
  125. elseif s:line1 =~ '^\s*dnl\>'
  126.     \ || getline(2) =~ '^\s*dnl\>'
  127.     \ || getline(3) =~ '^\s*dnl\>'
  128.     \ || getline(4) =~ '^\s*dnl\>'
  129.     \ || getline(5) =~ '^\s*dnl\>'
  130.   set ft=m4
  131.  
  132. " AmigaDos scripts
  133. elseif $TERM == "amiga"
  134.     \ && (s:line1 =~ "^;" || s:line1 =~ '^\.[bB][rR][aA]')
  135.   set ft=amiga
  136.  
  137. " SiCAD scripts (must have procn or procd as the first line to trigger this)
  138. elseif s:line1 =~ '^ *[pP][rR][oO][cC][nNdD] *$'
  139.   set ft=sicad
  140.  
  141. " Purify log files start with "****  Purify"
  142. elseif s:line1 =~ '^\*\*\*\*  Purify'
  143.   set ft=purifylog
  144.  
  145. " XML
  146. elseif s:line1 =~ '<?\s*xml.*?>'
  147.   set ft=xml
  148.  
  149. " XXD output
  150. elseif getline(1) =~ '^\x\{7}: \x\{2} \=\x\{2} \=\x\{2} \=\x\{2} '
  151.   set ft=xxd
  152.  
  153. " RCS/CVS log output
  154. elseif s:line1 =~ '^RCS file:' || getline(2) =~ '^RCS file:'
  155.   set ft=rcslog
  156.  
  157. " CVS commit
  158. elseif getline(2) =~ '^CVS:'
  159.    set ft=cvs
  160.  
  161. " SNNS files
  162. elseif s:line1 =~ '^SNNS network definition file'
  163.   set ft=snnsnet
  164. elseif s:line1 =~ '^SNNS pattern definition file'
  165.   set ft=snnspat
  166. elseif s:line1 =~ '^SNNS result file'
  167.   set ft=snnsres
  168.  
  169. " Virata
  170. elseif s:line1 =~ '^%.\{-}[Vv]irata'
  171.     \ || getline(2) =~ '^%.\{-}[Vv]irata'
  172.     \ || getline(3) =~ '^%.\{-}[Vv]irata'
  173.     \ || getline(4) =~ '^%.\{-}[Vv]irata'
  174.     \ || getline(5) =~ '^%.\{-}[Vv]irata'
  175.   set ft=virata
  176.  
  177. " Website MetaLanguage
  178. elseif s:line1 =~ '^#!.*wml.*'
  179.   set ft=wml
  180.  
  181. " Strace
  182. elseif s:line1 =~ '^execve('
  183.   set ft=strace
  184.  
  185. " VSE JCL
  186. elseif s:line1 =~ '^\* $$ JOB\>' || s:line1 =~ '^// *JOB\>'
  187.   set ft=vsejcl
  188.  
  189. " TAK and SINDA
  190. elseif getline(4) =~ 'K & K  Associates' || getline(2) =~ 'TAK 2000'
  191.   set ft=takout
  192. elseif getline(3) =~ 'S Y S T E M S   I M P R O V E D '
  193.   set ft=sindaout
  194. elseif getline(6) =~ 'Run Date: '
  195.   set ft=takcmp
  196. elseif getline(9) =~ 'Node    File  1'
  197.   set ft=sindacmp
  198.  
  199. " DNS zone files
  200. elseif getline(1) =~ '\($ORIGIN\|$TTL\|IN\s*SOA\)'
  201.       \ || getline(2) =~ '\($ORIGIN\|$TTL\|IN\s*SOA\)'
  202.       \ || getline(1).getline(2).getline(3).getline(4) =~ 'BIND.*named'
  203.   set ft=dns
  204.  
  205.  
  206. endif
  207.  
  208. " Restore 'cpoptions'
  209. let &cpo = s:cpo_save
  210.  
  211. unlet s:cpo_save s:line1
  212.